from rest_framework.exceptions import ValidationError


def filtering_admin_notes(request, notes):
    params = request.query_params
    if 'start_date' in params and 'end_date' not in params:
        start_date = params['start_date']
        notes = notes.filter(date=start_date)

    elif 'start_date' in params and 'end_date' in params:
        start_date = params['start_date']
        end_date = params['end_date']

        if start_date > end_date:
            raise ValidationError(
                'Start date must be lower than end date.')

        notes = notes.filter(date__range=[start_date, end_date])

    return notes